package com.example.administrator.officeplatform.kj;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.SearchView;
import android.widget.Toast;

import com.example.administrator.officeplatform.MyApplication;
import com.example.administrator.officeplatform.R;
import com.example.administrator.officeplatform.adapter.PersonAdapter;
import com.example.administrator.officeplatform.adapter.TimeSearchAdapter;
import com.example.administrator.officeplatform.base.BaseActivity;
import com.example.administrator.officeplatform.bean.PersonInfo;
import com.example.administrator.officeplatform.bean.TimeInfo;
import com.example.administrator.officeplatform.utils.JsonUtil;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class TimeActivity extends BaseActivity {
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.rv)
    RecyclerView rv;
    private Context mContext;
    private List<RelativeLayout> ls_rl;
    private List<View> ls_v;
    private List<TimeInfo> ls_audit = new ArrayList<>();
    private TimeSearchAdapter personAdapter;
    private OkHttpClient mOkHttpClient;
    private String newtext = "孙";
    private String index;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_time);

    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
        mContext=this;
        //设置布局管理器
        rv.setLayoutManager(new LinearLayoutManager(mContext));
        rv.setHasFixedSize(true);
        rv.setItemAnimator(new DefaultItemAnimator());

    }

    @Override
    protected void initData() {
        toolbar.setTitle("归属周期");
        index=(String)getIntent().getExtras().get("index");
        ls_audit= new ArrayList<>();
    }

    @Override
    protected void initEvents() {
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

//    private void search(){
//
//        mOkHttpClient = new OkHttpClient();
//        Request request = new Request.Builder()
//                .url(IpUtil.getIP()+"/reimbursement/setlecvcle/setlecycleList")
//                .header("cookie", MyApplication.getMsession())
//                .build();
//        Call call = mOkHttpClient.newCall(request);
//        call.enqueue(new Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
//                runOnUiThread(new Runnable() {
//                    @Override
//                    public void run() {
//                        Toast.makeText(mContext, "连接异常", Toast.LENGTH_SHORT).show();
//                    }
//                });
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) throws IOException {
//                String str = response.body().string();
//                final List<TimeInfo> lsMap = JsonUtil.getPersons(str, new TypeToken<List<TimeInfo>>() {
//                }.getType());
//                ls_audit.addAll(lsMap);
//                runOnUiThread(new Runnable() {
//                    @Override
//                    public void run() {
//                        if(ls_audit.size()==0){
//                            Toast.makeText(mContext, "未查询到周期信息", Toast.LENGTH_SHORT).show();
//                        }
//                        if(personAdapter==null){
//                            personAdapter=new TimeSearchAdapter(ls_audit,mContext);
//                            rv.setAdapter(personAdapter);
//                        }else{
//                            personAdapter.notifyDataSetChanged();
//                        }
//                        personAdapter.setOnRecyclerViewListener(new TimeSearchAdapter.OnRecyclerViewListener() {
//                            @Override
//                            public void onItemClick(int position) {
//                                Intent mIntent = new Intent();
//                                TimeInfo bmInfo = ls_audit.get(position);
//                                //把返回数据存入Intent
//                                mIntent.putExtra("index", index);
//                                mIntent.putExtra("person", bmInfo.getText());
//                                mIntent.putExtra("id", bmInfo.getId());
//                                //设置返回数据
//                                setResult(3, mIntent);
//                                finish();
//                            }
//
//                            @Override
//                            public boolean onItemLongClick(int position) {
//                                return false;
//                            }
//                        });
//
//                    }
//                });
//            }
//
//        });
//
//
//    }
}
